home *** CD-ROM | disk | FTP | other *** search
/ Adobe Graphics & Publishing SDK 1996 December / Adobe Graphics & Publishing SDK 1996 December.iso / mac / After Effects 3.1 SDK Mac / Examples / I⁄O Samples / Filmstrip FXIF / FILM_Read.c < prev    next >
Text File  |  1996-06-04  |  4KB  |  212 lines

  1. /**
  2.     FILM_Read.c
  3.     
  4.     Part of the Adobe After Effects 3.1 SDK    
  5.     Copyright (c)1993-96, Adobe Systems Inc, All Rights Reserved.
  6.  
  7.     Revision History
  8.         1.0, created by dmw
  9. **/
  10.  
  11. #include "Film.h"
  12. #include "PIFormat.h"
  13. #include "PIFormatT.h"
  14. #include <QDOffscreen.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <Picker.h>
  18. #include <AppleEvents.h>
  19.  
  20.  
  21. void ReadPrepare (Ptr Stuff, long *data, short *result)
  22. {
  23.     FormatRecordPtr    fp = (FormatRecordPtr)Stuff;
  24.  
  25.     fp->maxData /= 4;
  26.     
  27.     *result = 0;
  28.     
  29. }
  30.  
  31. static OSErr ReadAtPos (
  32.             short    fRefNum,
  33.             long    pos,            /* >> from begin */
  34.             long    *bytes,            /* <> */
  35.             void    *data )
  36. {
  37.     OSErr        err = 0;
  38.  
  39.     err = SetFPos(fRefNum, fsFromStart, pos);
  40.     
  41.     if (!err) {
  42.         err = FSRead(fRefNum, bytes, data);
  43.     }
  44.  
  45.     return err;
  46. }
  47.  
  48.  
  49. static OSErr GetFilmstripRec (
  50.                 short            fRefNum,
  51.                 FilmStripRec    *filmstrip )
  52. {
  53.     OSErr err = 0;
  54.     long count = sizeof(FilmStripRec);
  55.     
  56.     err = SetFPos(fRefNum, fsFromLEOF, -sizeof(FilmStripRec));
  57.     
  58.     if (!err) {
  59.         err = FSRead(fRefNum, &count, filmstrip);
  60.     }
  61.     
  62.     if (!err) {
  63.         if (filmstrip->signature != 'Rand' || count != sizeof(FilmStripRec))
  64.             err = formatCannotRead;
  65.     }
  66.  
  67.     return err;
  68. }
  69.  
  70.  
  71. void ReadStart (Ptr Stuff, long *data, short *result)
  72. {
  73.     OSErr                err = 0;
  74.     FormatRecordPtr        fp = (FormatRecordPtr)Stuff;
  75.     FormatRecordTPtr    fpt = (FormatRecordTPtr)(Stuff - sizeof(TimeExtension));
  76.     short                fRefNum = fp->dataFork;
  77.  
  78.     TimeInfoHandle        ti;
  79.     FilmStripRec        filmstrip;
  80.  
  81.     DEBUG_STR("\pBegin Read Start");
  82.     
  83.     
  84.     err = GetFilmstripRec(fRefNum, &filmstrip);
  85.  
  86.     if (!err) {
  87.         ti = fpt->time_ext.time_info;
  88.         
  89.         (**ti).fixed_fps = filmstrip.framesPerSec * 65536.0;
  90.     
  91.         (**ti).duration.value = (65536 * filmstrip.numFrames) / filmstrip.framesPerSec;
  92.         (**ti).duration.scale = 65536;
  93.         
  94.         (**ti).poster_time.value = 0;
  95.         (**ti).poster_time.scale = 65536;
  96.         
  97.         strcpy(DH(ti)->read_name, "Filmstrip File");
  98.         DH(ti)->read_message[0] = 0;
  99.         
  100.         
  101.         fp->imageMode = plugInModeRGBColor;
  102.         fp->depth = 8;
  103.         fp->planes = 4;
  104.     
  105.         fp->imageHRes = 72 * 65536L;
  106.         fp->imageVRes = 72 * 65536L;
  107.     
  108.         fp->planeMap[0] = 0;
  109.         fp->planeMap[1] = 1;
  110.         fp->planeMap[2] = 2;
  111.         fp->planeMap[3] = 3;
  112.         
  113.         fp->imageSize.h = filmstrip.width;
  114.         fp->imageSize.v = filmstrip.height;
  115.     }    
  116.  
  117.     DEBUG_STR("\pleaving Read Start");
  118.     *result = err;
  119. }
  120.  
  121.  
  122. void ReadContinue (Ptr Stuff, long *data, short *result)
  123. {
  124.     OSErr                err = 0;
  125.     FormatRecordPtr        fp = (FormatRecordPtr)Stuff;
  126.     FormatRecordTPtr    fpt = (FormatRecordTPtr)(Stuff - sizeof(TimeExtension));
  127.  
  128.     TimeInfoHandle        ti;
  129.     double                time;
  130.     long                w, h;
  131.     Handle                imageH;
  132.     long                frame_num;
  133.     long                offset, bytes_to_read;
  134.     FilmStripRec        filmRec;
  135.     
  136.     DEBUG_STR("\pBegin Read Continue");
  137.  
  138.     err = GetFilmstripRec(fp->dataFork, &filmRec);
  139.  
  140.     if (!err) {
  141.         ti = fpt->time_ext.time_info;
  142.         time = (double)(DH(ti)->read_time.value) / (double)(DH(ti)->read_time.scale);
  143.     
  144.         frame_num = time * filmRec.framesPerSec;
  145.         
  146.         if (frame_num >= filmRec.numFrames)
  147.             frame_num = filmRec.numFrames - 1;
  148.             
  149.         w = fp->imageSize.h;
  150.         h = fp->imageSize.v;
  151.  
  152.         bytes_to_read = w * h * 4;
  153.         imageH = NewHandle(bytes_to_read);
  154.         
  155.         if (imageH) {
  156.             offset = frame_num * w * (h + filmRec.leading) * 4;
  157.             HLock(imageH);
  158.             
  159.             err = ReadAtPos(fp->dataFork, offset, &bytes_to_read, *imageH);
  160.             
  161.             if (!err) {
  162.                 fp->imageMode = plugInModeRGBColor;
  163.                 fp->depth = 8;
  164.                 fp->planes = 4;
  165.  
  166.                 fp->theRect.top = fp->theRect.left = 0;
  167.                 fp->theRect.bottom = h;
  168.                 fp->theRect.right = w;
  169.                 
  170.                 fp->loPlane = 0;
  171.                 fp->hiPlane = 3;
  172.                 fp->colBytes = 4;
  173.                 fp->rowBytes = w * 4;
  174.                 fp->planeBytes = 1;
  175.                 fp->data = *imageH;
  176.                 
  177.                 if (fp->advanceState) {
  178.                     (*fp->advanceState)();
  179.                 } else {
  180.                     *result = errPlugInHostInsufficient;
  181.                 }
  182.                 
  183.                 DisposeHandle(imageH);    
  184.                 
  185.                 fp->data = NULL;
  186.             }
  187.         } else {
  188.             err = memFullErr;
  189.         }
  190.     }
  191.  
  192.     if (!err) {
  193.         *result = 0;
  194.     } else {
  195.         *result = err;
  196.     }
  197.     
  198.     DEBUG_STR("\p leaving read continue");
  199.     
  200. }
  201.  
  202.  
  203. void ReadFinish (Ptr Stuff, long *data, short *result)
  204. {
  205.     FormatRecordPtr    fp = (FormatRecordPtr)Stuff;
  206.     DEBUG_STR("\p begin read finish");
  207.  
  208.  
  209.     DEBUG_STR("\p leaving read finish");
  210.     *result = 0;
  211. }
  212.